﻿@{
    ViewBag.Title = "RuleInfo";
}

@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
    <link href="~/Scripts/miniui/themes/default/medium-mode.css" rel="stylesheet" type="text/css" />
}

<form id="form1" method="post">

    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" name="SaveInfo" iconCls="icon-save" onclick="SaveInfo" plain="true">保存</a>
                    <a class="mini-button" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
                <td style="width:100%;">
                    <div id="ck1" name="ck1" class="mini-checkbox" style="margin-right:20px" readOnly="false" value="true" text="连续新增 "></div>
                </td>                
            </tr>
        </table>
    </div>

    <div name="Base" title="次卡分类" style="overflow:hidden;margin-top:10px;margin-left:5px">
        <table>
            <tr>
                <td width="100px" height="30px" align="right">充值类型：</td>
                <td width="200px" height="30px">
                    <input id="FDataType" name="FDataType" class="mini-combobox" style="width:200px;" TabIndex="0" value="0" data="DataType" onvaluechanged="typeChange" />
                </td>
                <td width="100px" height="30px" align="right">会员分类：</td>
                <td width="200px" height="30px">
                    @Html.Partial("~/Views/Modular/LookupMembersClass.cshtml")
                </td>
            </tr>
            <tr>
                <td width="100px" height="30px" align="right">
                    <div id="Amount">充值金额：</div>
                </td>
                <td width="200px" height="30px">
                    <input id="FAmount" name="FAmount" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false"
                           style="width:200px;" TabIndex="2" showbutton="false" format="#,0.00" value="0" align="right" />
                </td>
                <td width="100px" height="30px" align="right">状态：</td>
                <td width="200px" height="30px">
                    <input id="FState" name="FState" class="mini-combobox" style="width:200px;" TabIndex="4" value="1" data="StateType" />
                </td>
            </tr>
            <tr>
                <td width="100px" height="30px" align="right">
                    <div id="GiveAmt">赠送金额：</div>
                </td>
                <td width="200px" height="30px">
                    <input id="FGiveAmt" name="FGiveAmt" class="mini-spinner" minValue="-1" maxValue="99999999" changeOnMousewheel="false"
                           style="width:200px;" TabIndex="3" showbutton="false" format="#,0.00" value="0" />
                </td>
                <td width="100px" height="30px" align="right">是否累加：</td>
                <td width="200px" height="30px">
                    <input id="FAddingFlag" name="FAddingFlag" class="mini-combobox" style="width:200px;" TabIndex="5" value="0" data="AddingFlag" />
                </td>
            </tr>
            <tr>
                <td width="100px" height="30px" align="right">
                    <div id="GiveAmt">赠送积分：</div>
                </td>
                <td width="200px" height="30px">
                    <input id="FGivePoint" name="FGivePoint" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false"
                    style="width:200px;" TabIndex="3" showbutton="false" format="#" value="0" />
                </td>
                <td width="100px" height="30px" align="right">赠送礼券：</td>
                <td width="200px" height="30px">
                    @Html.Partial("~/Views/Modular/LookupCoupon.cshtml")
                </td>                
            <tr>
                <td width="100px" height="30px" align="right">上级赠送积分：</td>
                <td width="200px" height="30px">
                    <input id="FGivePoint1" name="FGivePoint1" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false"
                    style="width:200px;" TabIndex="3" showbutton="false" format="#" value="0" />
                </td>
                <td width="100px" height="30px" align="right">礼券数量：</td>
                <td width="200px" height="30px">
                    <input id="FCouponQty" name="FCouponQty" class="mini-spinner" minValue="1" maxValue="10" changeOnMousewheel="false"
                    style="width:200px;" TabIndex="2" showbutton="false" value="1" align="right" />                    
                </td>
            </tr>
            <tr>
                <td width="100px" height="30px" align="right">上上级赠送积分：</td>
                <td width="200px" height="30px">
                    <input id="FGivePoint2" name="FGivePoint2" class="mini-spinner" minValue="0" maxValue="99999999" changeOnMousewheel="false"
                    style="width:200px;" TabIndex="3" showbutton="false" format="#" value="0" />
                </td>
                <td width="100px" height="30px" align="right">开始时间：</td>
                <td width="200px" height="30px">
                    <input class="mini-datepicker" name="FBeginTime" format="yyyy-MM-dd" style="width:200px;" value="" TabIndex="7" />
                </td>
            </tr>
            <tr>
                <td width="100px" height="30px" align="right">备注：</td>
                <td width="200px" height="30px">
                    <input id="FRemark" name="FRemark" class="mini-textbox " style="width:200px;" TabIndex="6" />
                </td>
                <td width="100px" height="30px" align="right">结束时间：</td>
                <td width="200px" height="30px">
                    <input class="mini-datepicker" name="FEndTime" format="yyyy-MM-dd" style="width:200px;" value="" TabIndex="8" />
                </td>
            </tr>
        </table>
    </div>

    <input name="FItemID" class="mini-hidden" />
    <input name="FClassID" class="mini-hidden" />
</form>
<div style="margin-left:40px;margin-top:10px;">提示1：充值金额和赠送金额都为0时，前台可输入赠送金额；赠送次数为-1，前台可输入赠送次数。</div>
<div style="margin-left:40px;margin-top:10px;">提示2：充值金额和赠送金额都为0时，赠送积分为每元赠送多少积分，次卡的积分赠送在次卡方案设置。</div>
<div style="margin-left:40px;margin-top:10px;">提示3：不选择会员分类时，所有会员都适用该规则。</div>

<script>
    var DataType = [{ "id": "0", "text": "充值" },
    { "id": "1", "text": "充次数" }];
    var StateType = [{ "id": "1", "text": "正常" },
    { "id": "0", "text": "停用" }];
    var AddingFlag = [{ "id": "0", "text": "否" },
    { "id": "1", "text": "是" }];

    function FormShown() {
        mini.parse();
        var nowDate = new Date();
        mini.getbyName("FBeginTime").setValue(nowDate);
        nowDate.setDate(nowDate.getDate() + 1);
        mini.getbyName("FEndTime").setValue(nowDate);
    }

    //加载资料
    function SetInfoData(data) {
        if (data.action == "new") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            NewInfo();
        }
        else {
           $.post("GetRuleInfo", { json: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (mData) {
                var form = new mini.Form("form1");
               var mdata = mini.decode(mData);
                mini.getbyName("FItemID").setValue(mdata.data[0].FItemID);
                form.setData(mdata.data[0]);
                mini.getbyName("FMembersClassID").setText(mdata.data[0].FClassNumber);
                mini.getbyName("FMembersClassID").setValue(mdata.data[0].FClassID);
                mini.getbyName("FCouponNumber").setText(mdata.data[0].FCouponNumber);
                mini.getbyName("FCouponNumber").setValue(mdata.data[0].FCouponID);
                if (mdata.data[0].FDataType == 0) {
                    $("#GiveAmt").html("赠送金额：");
                    $("#Amount").html("充值金额：");
                    mini.getbyName("FGivePoint").setEnabled(true);
                }
                else {
                    $("#GiveAmt").html("赠送次数：");
                    $("#Amount").html("充值次数：");
                    mini.getbyName("FGivePoint").setValue(0);
                    mini.getbyName("FGivePoint").setEnabled(false);
                }
                if (mdata.data[0].FAddingFlag == 0)
                    mini.getbyName("FAddingFlag").setValue(0);
                else
                    mini.getbyName("FAddingFlag").setValue(1);
            });
        }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("0");
        mini.getbyName("FAmount").setValue("0");
        mini.getbyName("FGiveAmt").setValue("0");
        mini.getbyName("FRemark").setValue("");
        //$.post("DefaultMemClass", { json: '[{"mSystemAppID":"' + parent.window.getSystemAppID() + '"}]' }, function (data) {
        //    var mdata = mini.decode(data);
        //    if (mdata.data.length > 0) {
        //        mini.getbyName("FMembersClassID").setText(mdata.data[0].FNumber);
        //        mini.getbyName("FMembersClassID").setValue(mdata.data[0].FItemID);
        //        mini.getbyName("FMembersClassName").setValue(mdata.data[0].FName);
        //    }
        //});
    }

    //保存资料
    function SaveInfo() {
        mini.getbyName("SaveInfo").setEnabled(false);
        var form = new mini.Form("#form1");
        var data = form.getData(true, false);
        if (!validata(data)) {
            mini.getbyName("SaveInfo").setEnabled(true);
            return;
        }

        var json = mini.encode(data);
        $.post("SaveRule", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                NewInfo();
                if (mini.getbyName("ck1").getChecked() == false)
                    CloseWindow();
            }
            else {
                mini.alert("错误信息:" + ret.error);
            }
            mini.getbyName("SaveInfo").setEnabled(true);
        });
    }

    function validata(data) {
        if (data.FTimeClassID == '') {
            mini.alert("会员类型未选择");
            return false;
        }
        //if (data.FAmount <= 0) {
        //    mini.alert("充值金额必须大于>0");
        //    return false;
        //}
        //if (data.FGiveAmt < 0) {
        //    mini.alert("赠送金额必须大于等于>=0");
        //    return false;
        //}
        return true;
    }

    function typeChange() {
        var type = mini.getbyName("FDataType").getValue();
        if (type == "0") {
            $("#GiveAmt").html("赠送金额：");
            $("#Amount").html("充值金额：");
            mini.getbyName("FGivePoint").setEnabled(true);
        }
        else {
            $("#GiveAmt").html("赠送次数：");
            $("#Amount").html("充值次数：");
            mini.getbyName("FGivePoint").setValue(0);
            mini.getbyName("FGivePoint").setEnabled(false);
        }
    }
</script>

